package com.example.baidumap_a.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.example.baidumap_a.Activity.BlueToothActivity;
import com.example.baidumap_a.Activity.RechargeActivity;
import com.example.baidumap_a.CarouselImage.DataBean;
import com.example.baidumap_a.CarouselImage.ImageNetAdapter;
import com.example.baidumap_a.MapActivity;
import com.example.baidumap_a.R;
import com.youth.banner.Banner;
import com.youth.banner.indicator.RoundLinesIndicator;
import com.youth.banner.util.BannerUtils;


public class OneFragment extends Fragment {

    private View view;
    private Banner banner;
    private Button btn_bluetooth, btn_recharge, btn_park;
    private OneListener oneListener;

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        oneListener = (OneListener) context;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


    }



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_one, container, false);
        initView();

        return view;
    }

    private void initView() {
        //轮播图初始化
        banner = view.findViewById(R.id.banner_oneFg);
        banner.setAdapter(new ImageNetAdapter(DataBean.getTestData3()));
        banner.setIndicator(new RoundLinesIndicator(getContext()));
        banner.setIndicatorSelectedWidth((int) BannerUtils.dp2px(15));

        //按钮初始化
        btn_bluetooth = view.findViewById(R.id.btn_bluetooth_one);
        btn_recharge = view.findViewById(R.id.btn_recharge_one);
        btn_park = view.findViewById(R.id.btn_park_one);

        btn_bluetooth.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getContext(), BlueToothActivity.class);
                startActivity(intent);
            }
        });

        btn_recharge.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getContext(), RechargeActivity.class);
                intent.putExtra("username", oneListener.OneGetUsername());
                startActivity(intent);
            }
        });
        btn_park.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getContext(), MapActivity.class);
                intent.putExtra("username", oneListener.OneGetUsername());
                startActivity(intent);
            }
        });

    }

    public interface OneListener {
        String OneGetUsername();
    }

}
